package core;


import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import cPanes.CPane;

/*
 * An ActionListener which should be applied to all objects on any CPane. Captures mouse clicks and checks for CTRL and ALT modifiers to
 * pass to the parent pane, otherwise allows the 
 */
public class PassListener implements MouseListener, MouseMotionListener{

	public void mouseDragged(MouseEvent arg0) {
		CPane c = (CPane)arg0.getComponent().getParent();
		if (arg0.isAltDown() || arg0.isControlDown()){
			MouseEvent e = new MouseEvent(c, arg0.getID(), arg0.getWhen(),arg0.getModifiers(), arg0.getX(), arg0.getY(), arg0.getClickCount(), arg0.isPopupTrigger());
			arg0.consume();
			c.mouseDragged(e);
		}
		
	}

	public void mouseMoved(MouseEvent arg0) {
		CPane c = (CPane)arg0.getComponent().getParent();
		if (arg0.isAltDown() || arg0.isControlDown()){
			MouseEvent e = new MouseEvent(c, arg0.getID(), arg0.getWhen(),arg0.getModifiers(), arg0.getX(), arg0.getY(), arg0.getClickCount(), arg0.isPopupTrigger());
			arg0.consume();
			c.mouseMoved(e);
		}
	}

	public void mouseClicked(MouseEvent arg0) {
		CPane c = (CPane)arg0.getComponent().getParent();
		if (arg0.isAltDown() || arg0.isControlDown()){
			MouseEvent e = new MouseEvent(c, arg0.getID(), arg0.getWhen(),arg0.getModifiers(), arg0.getX(), arg0.getY(), arg0.getClickCount(), arg0.isPopupTrigger());
			arg0.consume();
			c.mouseClicked(e);
		}
		
	}

	public void mouseEntered(MouseEvent arg0) {
		CPane c = (CPane)arg0.getComponent().getParent();
		if (arg0.isAltDown() || arg0.isControlDown()){
			MouseEvent e = new MouseEvent(c, arg0.getID(), arg0.getWhen(),arg0.getModifiers(), arg0.getX(), arg0.getY(), arg0.getClickCount(), arg0.isPopupTrigger());
			arg0.consume();
			c.mouseEntered(e);
		}
	}

	public void mouseExited(MouseEvent arg0) {
		CPane c = (CPane)arg0.getComponent().getParent();
		if (arg0.isAltDown() || arg0.isControlDown()){
			MouseEvent e = new MouseEvent(c, arg0.getID(), arg0.getWhen(),arg0.getModifiers(), arg0.getX(), arg0.getY(), arg0.getClickCount(), arg0.isPopupTrigger());
			arg0.consume();
			c.mouseExited(e);
		}
	}

	public void mousePressed(MouseEvent arg0) {
		CPane c = (CPane)arg0.getComponent().getParent();
		if (arg0.isAltDown() || arg0.isControlDown()){
			MouseEvent e = new MouseEvent(c, arg0.getID(), arg0.getWhen(),arg0.getModifiers(), arg0.getX(), arg0.getY(), arg0.getClickCount(), arg0.isPopupTrigger());
			arg0.consume();
			c.mousePressed(e);
		}
		
	}

	public void mouseReleased(MouseEvent arg0) {
		CPane c = (CPane)arg0.getComponent().getParent();
		if (arg0.isAltDown() || arg0.isControlDown()){
			MouseEvent e = new MouseEvent(c, arg0.getID(), arg0.getWhen(),arg0.getModifiers(), arg0.getX(), arg0.getY(), arg0.getClickCount(), arg0.isPopupTrigger());
			arg0.consume();
			c.mouseReleased(e);
		}
		
		
	}

}
